Creates a new item change observable for OPC item, specifying machine name, server class, item ID, requested update rate, and percent deadband.
Syntax
Parameters
- machineName
- Name of the machine (empty string for local computer).
- serverClass
- Contains ProgID of the OPC server.
- itemId
- ID of the item that will be subscribed to.
- requestedUpdateRate
- How often should the updates be received (number of milliseconds)
- percentDeadband
- The percent change in an item value that will cause an update
Type Parameters
- TValue
Return Value
Returns an observable for changes in the given OPC item.
Example
.NET
// Shows how to create an observable for OPC-DA item changes, and subscribe to it with percent deadband.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
using System;
using System.Threading;
using OpcLabs.EasyOpc.DataAccess.Reactive;
namespace ReactiveDocExamples
{
namespace _DAItemChangedObservable
{
partial class Subscribe
{
public static void PercentDeadband()
{
const float percentDeadband = 5.0f;
Console.WriteLine($"Creating observable with {percentDeadband}% deadband...");
DAItemChangedObservable<double> ramp =
DAItemChangedObservable.Create<double>("", "OPCLabs.KitServer.2", "Simulation.Ramp 0:100 (10 s)",
requestedUpdateRate:100, percentDeadband:percentDeadband);
Console.WriteLine("Subscribing...");
using (ramp.Subscribe(e => Console.WriteLine(
(e.Exception is null) ? e.Vtq.ToString() : e.Exception.GetBaseException().ToString())))
{
Console.WriteLine("Waiting for 10 seconds...");
Thread.Sleep(10*1000);
Console.WriteLine("Unsubscribing...");
}
Console.WriteLine("Waiting for 2 seconds...");
Thread.Sleep(2 * 1000);
}
}
}
}
Requirements
Target Platforms: .NET Framework: Windows 10 (selected versions), Windows 11 (selected versions), Windows Server 2016, Windows Server 2022; .NET: Linux, macOS, Microsoft Windows
See Also